package com.atguigu.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/send")
public class ProductorController {

    @Autowired
    RabbitTemplate rabbitTemplate;//自动配置 初始化的rabbitmq模板对象，通过它可以发送消息到mq
    @GetMapping("{msg}")
    public String sendMsg(@PathVariable("msg") String msg){
        //将消息发送到消息队列
        //如果交换机不存在 会报以下错误
        //reply-code=404, reply-text=NOT_FOUND - no exchange 'spring.test.exchange' in vhost '/vh211027'
        //参数1：交换机名称 ， 参数2：路由key ， 参数3: 消息
        rabbitTemplate.convertAndSend("spring.test1.exchange","a.b.c",msg);
        return "success";
    }
    @GetMapping("test2/{msg}")
    public String sendTest2Msg(@PathVariable("msg") String msg){
        //将消息发送到消息队列
        //如果交换机不存在 会报以下错误
        //reply-code=404, reply-text=NOT_FOUND - no exchange 'spring.test.exchange' in vhost '/vh211027'
        //参数1：交换机名称 ， 参数2：路由key ， 参数3: 消息
        rabbitTemplate.convertAndSend("test2_service_exchange","test2.b.c",msg);
        return "success";
    }
}
